package com.javayh.controller;

import com.javayh.bean.JsonDate;
import com.javayh.dao.TreeDao;
import com.javayh.entity.Role;
import com.javayh.entity.TreeDemoEntity;
import com.javayh.util.tree.BuildTree;
import com.javayh.util.tree.TreeNode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Dylan Yang
 * @Title: RoleController
 * @ProjectName lucky
 * @Description: TODO
 * @date 2018/10/217:14
 */
@RestController
@RequestMapping(value = "/role/")
@Api(value = "RoleController",tags = "RoleController")
public class RoleController extends BaseContrllor {

    /**
     * 新增角色信息
     * @author Dylan Yang
     */
    @GetMapping(value = "saveRole")
    @ApiOperation(value = "新增角色信息",notes = "saveRole")
    public JsonDate saveRole(Role role) {
        role.setName("超级管理员");
        role.setType("管理员");
        int saveRole = this.roleService.saveRole(role);
        if (saveRole > 0){
            return new JsonDate(200,"success","新增角色" + saveRole +"条成功！");
        }
        return new JsonDate(500,"error","角色信息增加失败");
    }

    /**
     * 修改角色信息
     * @author Dylan Yang
     */
    @GetMapping(value = "modfiyRole")
    @ApiOperation(value = "修改角色信息",notes = "modfiyRole")
    public JsonDate modfiyRole( Role role) {
        role.setId(10);
        role.setName("部门经理");
        role.setType("经理");
        int modfiyRole = this.roleService.modfiyRole(role);
        if (modfiyRole > 0 ){
            return new JsonDate(200,"success","修改角色"+modfiyRole+"条成功!");
        }
        return new JsonDate(500,"error","角色信息修改失败!");
    }

    @Autowired
    private TreeDao treeDao;

    @GetMapping("queryList")
    public  JsonDate queryList(){
        BuildTree buildTree=new BuildTree();
        List<TreeNode> list=treeDao.queryList();
        List<TreeNode> list2= buildTree.buildTree(list);
        return new JsonDate(200,"树节点展示",list);
    }
}

